package com.cskaoyan.controller;

import com.cskaoyan.module.bean.BaseRespVo;
import com.cskaoyan.module.bean.param.BaseParam;
import com.cskaoyan.module.bo.AdListParamBo;
import com.cskaoyan.module.bo.CouponListParamsBo;
import com.cskaoyan.module.pojo.MarketAd;
import com.cskaoyan.module.vo.MarketAdVo;
import com.cskaoyan.module.vo.MarketCouponVo;
import com.cskaoyan.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * AdController
 *
 * @param
 * @return
 * @2022/4/7
 **/
@RestController
@RequestMapping("admin/ad")
public class AdController {
    @Autowired
    @Qualifier("adServiceImpl")
    AdService adService;

    @RequestMapping("list")
    public BaseRespVo<MarketAdVo> list(BaseParam baseParam,String name,String content) {
        MarketAdVo marketAdVo=null;
        BaseRespVo ok=null;
        AdListParamBo params=new AdListParamBo();
        params.setLimit(baseParam.getLimit());
        params.setOrder(baseParam.getOrder());
        params.setPage(baseParam.getPage());
        params.setSort(baseParam.getSort());
//            优惠卷不限制 ->根据limit=0查询

        if (name != null) {
            params.setName(name);
        } else {
            params.setName("");
        }
        if (content != null) {
            params.setContent(content);
        } else {
            params.setContent("");
        }
        marketAdVo=adService.list(params);

        ok = new BaseRespVo();
        ok.setErrmsg("成功");
        ok.setData(marketAdVo);
        System.out.println("ad list ok = " + ok);
    return  ok;
    }
    @RequestMapping("create")
    public BaseRespVo<MarketAd> create(@RequestBody MarketAd params) {
        MarketAd marketAd=null;
        BaseRespVo ok=null;
        marketAd=adService.create(params);

        ok = new BaseRespVo();
        ok.setErrmsg("成功");
        ok.setData(marketAd);
        System.out.println("ad list ok = " + ok);
        return  ok;
    }
    @RequestMapping("update")
    public BaseRespVo<MarketAd> update(@RequestBody MarketAd params) {
        MarketAd marketAd=null;
        BaseRespVo ok=null;
        marketAd=adService.update(params);

        ok = new BaseRespVo();
        ok.setErrmsg("成功");
        ok.setData(marketAd);
        System.out.println("ad list ok = " + ok);
        return  ok;
    }
    @RequestMapping("delete")
    public BaseRespVo<MarketAd> delete(@RequestBody MarketAd params) {
        int code = adService.delete(params);
        if (code == 0) {
            return BaseRespVo.invalidData();
        } else {
            return BaseRespVo.ok("成功");
        }
    }


}
